Skip to main content

Common Problems

Undo unstaged local changes

To overwrite local changes:

git checkout -- <file>

To discard local changes to all files, permanently:

git reset --hard

Undo staged local changes

To unstage the file but keep your changes:

git restore --staged <file>

To unstage everything but keep your changes:

git reset

To discard local changes to all files, permanently:

git reset --hard

Undo committed local changes

This is a always a bit harder... To undo last two commits, but keep your changes:

git reset HEAD~2       

To undo last two commits, discard changes:

git reset --hard HEAD~2 

Change commit

To change the message of the last commit:

git commit --amend -m "New message"

Did you forget to add a file? Just add it and amend the previous commit :)

git add forgotten_file
git commit --amend